package com.rong.structural.bridgeModel;

/**
 * 桥接模式：实现手机品牌与样式之间的解耦
 * 一个类存在两个独立变化的维度，且这两个维度都需要进行扩展。
 */
public class PhoneTest {
    public static void main(String[] args) {
        // 获取折叠手机 + 品牌
        Phone zhediePhone = new ZhediePhone(new Xiaomi());
        zhediePhone.open();
        zhediePhone.call();
        zhediePhone.close();

    }
}

/**
 * 充当桥的作用
 */
abstract class Phone{
    // 组合品牌
    private Brand brand;

    // 构造器
    public Phone(Brand brand){
        super();
        this.brand = brand;
    }
    protected void open(){
        brand.open();
    }
    protected void close(){
        brand.close();
    }
    protected void call(){
        brand.call();
    }



}

class ZhediePhone extends Phone{

    public ZhediePhone(Brand brand) {
        super(brand);
    }

    public void open() {
        super.open();
        System.out.println("折叠手机");
    }

    public void close() {
        super.close();
        System.out.println("折叠手机");

    }

    public void call(){
        super.call();
        System.out.println("折叠手机");
    }
}

class FangaiPhone extends Phone{

    public FangaiPhone(Brand brand){
        super(brand);
    }

    public void open() {
        super.open();
        System.out.println("翻盖手机");
    }

    public void close() {
        super.close();
        System.out.println("翻盖手机");
    }

    public void call(){
        super.call();
        System.out.println("翻盖手机");
    }
}

interface Brand{
    void call();
    void  open();
    void  close();
}

class Vivo implements Brand{

    @Override
    public void call() {
        System.out.println("Vivo手机打电话");
    }

    @Override
    public void open() {
        System.out.println("Vivo手机开机");

    }

    @Override
    public void close() {
        System.out.println("Vivo手机关机");

    }
}

class Xiaomi implements Brand{

    @Override
    public void call() {
        System.out.println("Xiaomi手机打电话");
    }

    @Override
    public void open() {
        System.out.println("Xiaomi手机开机");

    }

    @Override
    public void close() {
        System.out.println("Xiaomi手机关机");

    }
}

class Redmi implements Brand{

    @Override
    public void call() {
        System.out.println("Redmi手机打电话");
    }

    @Override
    public void open() {
        System.out.println("Redmi手机开机");

    }

    @Override
    public void close() {
        System.out.println("Redmi手机关机");

    }
}
